base_convert
Convert numbers between any binary
base_convert()
function converts numbers between arbitrary bits.
Convert hexadecimal numbers to octal numbers:
<?php $hex = "E196" ; echo base_convert ( $hex , 16 , 8 ) ; ?>
Try it yourself
Convert octal numbers to decimal numbers:
<?php $oct = "0031" ; $dec = base_convert ( $oct , 8 , 10 ) ; echo "The octal $oct is equal to the decimal $dec ." ; ?>
Try it yourself
Convert octal numbers to hexadecimal numbers:
<?php $oct = "364" ; $hex = base_convert ( $oct , 8 , 16 ) ; echo "The octal $oct is equal to the hex $hex ." ; ?>
Try it yourself
base_convert ( number , frombase , tobase )
parameter | describe |
---|---|
number | Required. Original value. |
frombase | Required. The original number of the digital. |
tobase | Required. The binary to be converted. |
Returns a string containing the number expressed in tobase . The number itself's binary system is specified by frombase . Both frombase and tobase can only be between 2 and 36 (including 2 and 36). Numbers higher than decimal are represented by the letter az, for example a means 10, b means 11 and z means 35.